package com.example.controller;

import com.example.pojo.PageBean;
import com.example.pojo.Quality;
import com.example.pojo.Result;
import com.example.pojo.Task;
import com.example.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/qual")
public class QualityController {

    @Autowired
    private QualityService qualityService;
    @GetMapping
    public Result selectAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                            @RequestParam(defaultValue = "0")int inspectorID, String result ,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = qualityService.page(page, pageSize, inspectorID, result, begin, end);
        return Result.success(pageBean);
    }

    @GetMapping("/one")
    public Result selectone(int taskID) {
        Task task = qualityService.selectone(taskID);
        return Result.success(task);
    }
    @PostMapping
    public Result add(@RequestBody Quality quality){
        qualityService.add(quality);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int[] id){
        qualityService.delete(id);
        return Result.success();
    }

}
